package com.cyz.web.app.asyncTool.test;

import com.cyz.web.app.asyncTool.tools.callback.ICallback;
import com.cyz.web.app.asyncTool.tools.callback.IWorker;
import com.cyz.web.app.asyncTool.tools.executor.timer.SystemClock;
import com.cyz.web.app.asyncTool.tools.worker.WorkResult;
import com.cyz.web.app.asyncTool.tools.wrapper.WorkerWrapper;

import java.util.Map;

public class ParWork implements IWorker<String, String>, ICallback<String, String> {
    @Override
    public void result(boolean success, String param, WorkResult<String> workResult) {
        if (success) {
            System.out.println("callback worker success--" + SystemClock.now() + "----" + workResult.getResult()
                    + "-threadName:" + Thread.currentThread().getName());
        } else {
            System.err.println("callback worker failure--" + SystemClock.now() + "----" + workResult.getResult()
                    + "-threadName:" + Thread.currentThread().getName());
        }
    }

    @Override
    public String action(String object, Map<String, WorkerWrapper> allWrappers) {
        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        return "result = " + SystemClock.now() + " --param = " + object + " from 0 ";
    }

    @Override
    public String defaultValue() {
        return "worker--default";
//        return IWorker.super.defaultValue();
    }
}
